<?php

class DispatchBoard extends ActiveRecord{
    const STATUS_ACTIVE = 0;
    const STATUS_INACTIVE = 1;

    public static function model($className=__CLASS__){
        return parent::model($className);
    }
    public function tableName() {
        return "tbl_dispatch_board";
    }
    public function rules(){
        return array(
            array('description,status','required'),
            array('id,status','numerical'),
            array('description','length','max'=>50)
        );
    }
    public function attributeLabels() {
        return array(
            'id'=>'ID',
            'description'=>'Description'
        );
    }

    public function getStatusList(){
        return array(
            self::STATUS_ACTIVE =>'Active',
            self::STATUS_INACTIVE =>'Inactive'
        );
    }

    public function getStatusText(){
        return isset($this->statusList[$this->status])?$this->statusList[$this->status]:null;
    }
    public static function getList(){
        $list=Yii::app()
                    ->db
                    ->createCommand('select * from tbl_dispatch_board where status=:status order by sort')
                    ->bindValues(array('status'=>self::STATUS_ACTIVE))
                    ->queryAll();
        $rs=array(
            NULL=>'N/A'
        );
        foreach($list as $item){
            $rs[$item['id']]=$item['description'];
        }
        return $rs;
    }
    public static function getListWithAll(){
        $list=Yii::app()
                    ->db
                    ->createCommand('select * from tbl_dispatch_board where status=:status order by sort')
                    ->bindValues(array('status'=>self::STATUS_ACTIVE))
                    ->queryAll();
        $rs=array(
            NULL=>'All'
        );
        foreach($list as $item){
            $rs[$item['id']]=$item['description'];
        }
        return $rs;
    }
}